new Vue({
	el: '#app',
	data: function () {
		return {
			loading:false,//进去的加载中显示
			host: window.location.protocol+'//'+window.location.host,
			communityId:'',
			msg:'请求超时',
			errorPopup:false,
			showErrorMsg:false,
			list:[],
			page:0,
			row:10,
			search_mobile_value:'',
			userId:'',
			load: false,
			finished: false,
      		refreshing: false,
			list_length:0,
			records:'',//总页数
			finished_text:'没有更多了',
			requestHeaders:'',
		}
	},
	created() {
		var localStorageCommunityId=JSON.parse(localStorage.getItem('hc_currentCommunityInfo'))
		if(localStorageCommunityId){
			this.communityId=localStorageCommunityId.communityId?localStorageCommunityId.communityId:this.getUrlParam("communityId");
		}else{
			this.communityId=this.getUrlParam("communityId");
		}
		this.requestHeaders=getRequestHeaders('00',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
	},
	mounted(){
		var that=this;
	},
	filters: {
		subStringThree: function (value) {
			if (!value) return ''
			return value.substring(0,3)
		}
	},
	methods: {
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
	  
		},
	
		searchBtn(){
			this.page=0;
			this.row=10;
			this.list = [];
			this.onDownRefresh()
		},
		clickExamine(auditId){
			window.location.href="../../examineDetail.html?auditId="+auditId
		},
		loadListData(){
			let that=this;
			let url=this.host+'/app/userAudit.listUserAudits';
			let params={
				page: this.page,
				row: this.row,
				mobile:that.search_mobile_value,
				identityTypes:['1001','1002','1012','1003'],
				approveUserId:'',
			}
			console.log('查询第'+params.page+'页')
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询审核列表',res);
					if(res.code=='0'){
						that.records=res.records;
						var loadList=res.data;
						that.list_length=loadList.length;
						if(that.list_length<1){
							that.finished_text=''
						}else{
							that.finished_text='没有更多了'
						}
						if( loadList==null || loadList=='' || that.list_length == 0){
							that.list = [];
							// 加载结束
							that.refreshing=false
							that.load = false;
							that.finished = true;
							return
						}
						if (that.refreshing) {
							that.list = [];
							that.refreshing = false;
						}
						 if (that.page === 1) {
							that.list = loadList
						} else {
							that.list = that.list.concat(loadList)
						}
						that.load = false;
						if (that.page == that.records) {
							that.finished = true;
						}
						
					}else{
						that.refreshing=false
						that.load = false;
						that.finished_text='';
						that.finished = true;
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.refreshing=false
					that.load = false;
					that.finished_text='';
					that.finished = true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		onDownRefresh() {
            this.page++;
            this.finished = false // 不写这句会导致你上拉到底过后在下拉刷新将不能触发下拉加载事件
            this.loadListData() // 加载数据
        },
		onRefresh() {
			var that=this;
            // 清空列表数据
            that.finished = false;
            if(that.list_length<=0){
                that.refreshing=false;
            }
            // 重新加载数据
            // 将 loading 设置为 true，表示处于加载状态
            that.load = true;
            that.page=1;
            setTimeout(function(){
              that.loadListData();
            },1000)
        },
	}
});